﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;


namespace TBG.TBG_F
{
    class Timer
    {
        Texture2D _NUMBERS;
        int frameWidth = 48;
        int frameCount = 6;
        int currentFrame = 0;

        float frameRate = 1f;
        float fElapsed = 0.0f;

        public bool PlayerTurn = false;
        SpriteFont _font;

        public Timer(ContentManager content)
        {
            _NUMBERS = content.Load<Texture2D>("Numbers");
            PlayerTurn = true;

            _font = content.Load<SpriteFont>("Pericles8");
        }

        public void Update(GameTime gameTime)
        {
            fElapsed += (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (fElapsed >= frameRate)
            {
                currentFrame = (currentFrame + 1) % frameCount;
                fElapsed = .0f;
                if (currentFrame == 0)
                {
                    changeTurn();
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(_NUMBERS, new Vector2(485, 15), getSourceRect(), Color.White);
            spriteBatch.DrawString(_font, PlayerTurn.ToString(), new Vector2(485, 25), Color.White);
        }

        private Rectangle getSourceRect()
        {
            return new Rectangle(currentFrame * frameWidth, 0, frameWidth, 48);
        }

        void changeTurn()
        {
            PlayerTurn = !PlayerTurn;
        }
    }
}
